/*******************************************************************************
 * This code is totally free to edit and be distributed
 * Author: José Manuel Portero García (jmporterog@gmail.com)
 ******************************************************************************/
package gazpachito.examples.dozer.mapper;

import java.util.ArrayList;
import java.util.List;

import etm.core.configuration.EtmManager;
import etm.core.monitor.EtmMonitor;
import etm.core.monitor.EtmPoint;
import gazpachito.examples.dozer.facade.ChildBO;
import gazpachito.examples.dozer.facade.ParentBO;
import gazpachito.examples.dozer.persistence.ChildVO;
import gazpachito.examples.dozer.persistence.ParentVO;

import org.dozer.DozerBeanMapper;

/**
 * @author jmporterog
 *
 */
public class DozerParentMapper implements ParentMapper {

	private static final EtmMonitor ETM_MONITOR = EtmManager.getEtmMonitor();
	
	protected DozerBeanMapper mapper;
	
	public DozerParentMapper() {
		List<String> myMappingFiles = new ArrayList<String>();
		myMappingFiles.add("dozerBeanMapping.xml");
		mapper = new DozerBeanMapper();
		mapper.setMappingFiles(myMappingFiles);
	}
	
	/* 
	 * (non-Javadoc)
	 * @see gazpachito.examples.dozer.mapper.ParentMapper#map(gazpachito.examples.dozer.persistence.ParentVO)
	 */
	public ParentBO map(ParentVO parentVO) {
		EtmPoint point = ETM_MONITOR.createPoint("DozerParentMapper:map");
		
		ParentBO parentBO = this.mapper.map(parentVO, ParentBO.class);
		
		point.collect();

		return parentBO;
	}
	
	/*
	 * (non-Javadoc)
	 * @see gazpachito.examples.dozer.mapper.ParentMapper#map(gazpachito.examples.dozer.persistence.ChildVO)
	 */
	public ChildBO map(ChildVO childVO) {
		return this.mapper.map(childVO, ChildBO.class);
	}
}
